package org.kca.yarmour.data;

import org.kca.yarmour.YAException;
import org.kca.yarmour.data.GlobalData.InvItemType;
import org.kca.yarmour.yadata.ItemType;
import org.kca.yarmour.yadata.VehicleStatsType;

public class InvItem
{
    private String id, name, description;
    private InvItemType type;
    private int space, price;
    private boolean usable;
    
    public InvItem(String id, String name, InvItemType type)
    {
        this.id = id;
        this.name = name;
        this.type = type;
    }
    
    /**
     * Gets the id
     * @return the id
     */
    public String getId()
    {
        return id;
    }
    
    /**
     * Gets the name
     * @return the name
     */
    public String getName()
    {
        return name;
    }
    
    /**
     * Gets the type of item
     * @return the type
     */
    public InvItemType getType()
    {
        return type;
    }
    
    /**
     * Gets the space occupied by the item
     * @return the space
     */
    public int getSpace()
    {
        return space;
    }
    
    /**
     * Gets the price of the item
     * @return the price
     */
    public int getPrice()
    {
        return price;
    }
    
    /**
     * Gets the description of the item
     * @return the description
     */
    public String getDescription()
    {
        return description;
    }
    
    /**
     * Sets the description of the item
     * @param description the description to set
     */
    public void setDescription(String description)
    {
        this.description = description;
    }
    
    /**
     * Creates a item based on details specified in XML
     * @param itype the XML item type
     * @return an inventory item object
     */
    public static InvItem createFromXmlType(ItemType itype)
    {
        InvItemType type = InvItemType.getItemType(itype.getType());
        if (type == null)
        {
            throw new YAException("Illegal item type: " + itype.getType());
        }
        InvItem item = new InvItem(itype.getId(), itype.getName(), type);
        item.price = itype.getPrice();
        item.space = itype.getSpace();
        item.description = itype.getDesc();
        item.usable = itype.isUsable();
        return item;
    }
    
}
